<template>
  <div class="app-container">
    <el-form :inline="true" class="demo-form-inline" label-position="left">

      <el-form-item label="用户账号">
        <el-input v-model="userQuery.userName" style="width: 150px" placeholder="用户账号"/>
      </el-form-item>

      <el-form-item label="用户类型">
        <el-select
          v-model="userQuery.userType"
          style="width: 150px"
          placeholder="用户类型">
          <el-option
            v-for="option in userTypeOptions"
            :key="option.value"
            :label="option.label"
            :value="option.value"/>
        </el-select>
      </el-form-item>

      <el-form-item label="联系电话">
        <el-input v-model="userQuery.tel" style="width: 150px" placeholder="联系电话"/>
      </el-form-item>

      <el-form-item label="审核状态">
        <el-select
          v-model="userQuery.judgeFlag"
          style="width: 150px"
          placeholder="审核状态">
          <el-option
            v-for="option in judgeFlagOptions"
            :key="option.value"
            :label="option.label"
            :value="option.value"/>
        </el-select>
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="getList()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>
    <!-- 表格 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="数据加载中"
      border
      fit
      highlight-current-row>

      <el-table-column label="用户账号" align="center" prop="userName" />

      <el-table-column label="用户名称" align="center" prop="userRealName"/>

      <el-table-column label="用户类型" align="center">
        <template slot-scope="scope">
          <div v-if="scope.row.userType == '1'">
            <el-tag type="warning" effect="plain"> 菜农 </el-tag>
          </div>
          <div v-else-if="scope.row.userType == '2'">
            <el-tag type="" effect="plain"> 菜企 </el-tag>
          </div>
          <div v-else-if="scope.row.userType == '3'">
            <el-tag type="success" effect="plain"> 菜商 </el-tag>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="联系方式" align="center" prop="tel" />

      <el-table-column label="地址" align="center" prop="address" />

      <el-table-column label="身份证正面" align="center" width="150px">
        <template slot-scope="scope">
          <div v-if="scope.row.idCardFront != undefined && scope.row.idCardFront != ''">
            <el-image :src="scope.row.idCardFront" :preview-src-list="[scope.row.idCardFront]" style="width: 120px; height: 80px"/>
          </div>
          <div v-else>
            无
          </div>
        </template>
      </el-table-column>

      <el-table-column label="身份证背面" align="center" width="150px">
        <template slot-scope="scope">
          <div v-if="scope.row.idCardBack != undefined && scope.row.idCardBack != ''">
            <el-image :src="scope.row.idCardBack" :preview-src-list="[scope.row.idCardBack]" style="width: 120px; height: 80px"/>
          </div>
          <div v-else>
            无
          </div>
        </template>
      </el-table-column>

      <el-table-column label="审核情况" align="center" >
        <template slot-scope="scope">
          <div v-if="scope.row.judgeFlag === '-1'">
            <el-tag type="danger"> 驳回 </el-tag>
          </div>
          <div v-else-if="scope.row.judgeFlag == '0'">
            <el-tag> 待审核 </el-tag>
          </div>
          <div v-else-if="scope.row.judgeFlag == '1'">
            <el-tag type="success"> 通过 </el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <router-link :to="'/user/detail/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-search">查看</el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="current"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getList"
    />
  </div>
</template>
<script>

import user from '@/api/trace/user'
export default {
  data() {
    return {
      productNames: [],
      listLoading: true,
      urlVisable: false,
      idCardPicList: [],
      judgeFlagOptions: [
        {
          value: -1,
          label: '驳回'
        }, {
          value: 0,
          label: '待审核'
        }, {
          value: 1,
          label: '通过'
        }
      ],
      userTypeOptions: [
        {
          value: 1,
          label: '菜农'
        }, {
          value: 2,
          label: '菜企'
        }, {
          value: 3,
          label: '菜商'
        }
      ],
      list: [],
      current: 1,
      limit: 5,
      total: 10,
      userQuery: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList(current = 1) {
      this.current = current
      user.getPageList(this.current, this.limit, this.userQuery)
        .then(response => {
          this.listLoading = false
          this.list = response.data.list
          this.total = response.data.total
        }).catch(response => {
          console.log('error')
        })
    },
    resetData() {
      this.userQuery = {}
      this.getList()
    },
    hidden() {
      this.urlVisable = false
    }
  }
}
</script>
